// 获取product

//获取参数
function getUrl(url){

var urlArr = url.split("?")[1];
 console.log( urlArr );

 urlArr = urlArr.split("&");
 console.log( urlArr );

 var obj = {};
urlArr.forEach( item => {
var itemarr = item.split("=");
obj[itemarr[0]] = itemarr[1];
 });
 return obj;
}

// 折扣详情页
(function(){
  var products = document.querySelector(".product");
    var urlStyring = decodeURI(location.href);
    console.log(urlStyring);

    var paraObj = getUrl(urlStyring);
    console.log(paraObj);  

var xhr = new XMLHttpRequest();
xhr.open("get","http://chst.vip:1234/api/getdiscountproduct?productid="+paraObj.productid,true);
xhr.send();
xhr.onreadystatechange = function(){
    if(xhr.readyState === 4 && xhr.status === 200){
        var res = JSON.parse(xhr.responseText);
        console.log(res);
        var rex = res.result;
        console.log(rex[0].productId);
        var ele = ""
          ele += `
          <div class="shop">
          <span>${rex[0].productName}</span>
          <span>${rex[0].productForm}${rex[0].productTime}${rex[0].productTips}</span>
          <span>${rex[0].productPrice}</span>
          <span>${rex[0].productInfo}</span>
           ${rex[0].productImg} 
         </div>   
          `
        products.innerHTML = ele;
    }

}

})();